/*
 * Copyright (C) 2008 ZXing authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.dtr.zxing.activity;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.tzpay.tzpay.R;
import com.tzpay.tzpay.ui.BaseActivity;

/**
 * This activity opens the camera and does the actual scanning on a background
 * thread. It draws a viewfinder to help the user place the barcode correctly,
 * shows feedback as the image processing is happening, and then overlays the
 * results when a scan is successful.
 *
 * @author dswitkin@google.com (Daniel Switkin)
 * @author Sean Owen
 */
public final class CaptureActivity extends BaseActivity {
    private static final String TAG = com.dtr.zxing.activity.CaptureActivity.class.getSimpleName();
    private CaptureFragment fragment;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        String title = getString(R.string.text_title_scan);
        changeTitle(title);
        fragment = CaptureFragment.instance();
        changeFragment(fragment, R.id.fragment_content);
        initTitle();
    }

    /**
     * 初始化标题栏
     */
    private void initTitle() {
        findViewById(R.id.layout_title1).setBackgroundColor(getResources().getColor(R.color.primary_half_alph));
        findViewById(R.id.btn_back).setOnClickListener(fragment);
        View rightView = findViewById(R.id.btn_right);
        rightView.setVisibility(View.GONE);
        findViewById(R.id.btn_right).setOnClickListener(fragment);
    }

    @Override
    public void setupContentView() {
        setContentView(R.layout.activity_capture);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            fragment.onBackPressed();
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBackPressed() {
        fragment.onBackPressed();
    }

}